package in.waffl.fairycake;

import java.awt.BorderLayout;
import java.awt.Color;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

public class MainWindow extends JFrame {
	private static final long serialVersionUID = -5019907534787661443L;
	private JPanel contentPane;
	private final Canvas canvas;


	public MainWindow()  {
		setTitle(Main.gameName);
		setResizable(false);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		contentPane = new JPanel();
		contentPane.setBackground(Color.BLACK);
		contentPane.setBorder(new EmptyBorder(0, 0, 0, 0));
		contentPane.setLayout(new BorderLayout(0, 0));
		setContentPane(contentPane);
		canvas = new Canvas();
		contentPane.add(canvas, BorderLayout.CENTER);
		pack();
	}
	public Canvas getCanvas() {
		return canvas;
	}
	
	@Override
	public void setVisible(boolean b) {
		super.setVisible(b);
		boolean success = false;
		while (!success) {
			try {
				canvas.createBufferStrategy(2);
				success = true;
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
		canvas.start();
	}
}
